﻿using System.Collections.Generic;

namespace ExFlash.Records
{
    public static class ClipActionAssistant
    {
        public static List<ClipActionRecord> GetClipActions(BinaryBitReader reader, int version)
        {
            List<ClipActionRecord> list = new List<ClipActionRecord>();

            // There's at least one clip action record.

            ClipActionRecord rec = new ClipActionRecord(version);
            rec.SwfDeserialize(reader);
            list.Add(rec);

            if (version <= 5)
            {
                while (reader.PeekUInt16() != 0)
                {
                    rec = new ClipActionRecord(version);
                    rec.SwfDeserialize(reader);
                    list.Add(rec);
                }

                reader.Position += 2;
            }
            else
            {
                while (reader.PeekUInt32() != 0)
                {
                    rec = new ClipActionRecord(version);
                    rec.SwfDeserialize(reader);
                    list.Add(rec);
                }

                reader.Position += 4;
            }

            return list;
        }
    }
}
